var e = getApp(), a = e.requirejs("core"), t = e.requirejs("wxParse/wxParse"), i = e.requirejs("biz/diypage"), s = e.requirejs("jquery");


Page({

  /**
   * 页面的初始数据
   */
  data: {
    tempFilePaths:[],
    check:true,
    id:'',
    title:'',
    content:'',
    
  },

  // 接口要的参数
  QueryParams:{
    id:''
  },
  TimeId:-1,
  /**
   * 生命周期函数--监听页面加载
   */
  // onLoad: function (options) {
  //   console.log(options);
  //  this.getinfo(this.data.id,this.data.title,this.data.content)
  // },
  onShow:function(){
    // console.log(this.data.cid);
    let bid=wx.getStorageSync('bid')
    // console.log(bid);
    // let title 
    this.setData({
      id:bid
    })
    // this.getinfo(this.data.id,this.data.title,this.data.content)
    // console.log(this.data.id);
  },
  // 调用相册方法
  chooseImage(){
    // console.log(11);
   const that = this
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success (res) {
        // tempFilePath可以作为img标签的src属性显示图片
        console.log(res);
        // const tempFilePaths = res.tempFilePaths
       const imagePath = res.tempFilePaths
       let tempFilePaths= that.data.tempFilePaths.concat(imagePath)
        that.setData({
          tempFilePaths
        })
      }
    })
  },

  // 点击打开图片选项卡
  checkimg(){
   let check=!this.data.check
  //  console.log(check);
   this.setData({
    check
   })
  },
  // 删除图片
  canlimg(e){
  let index = e.currentTarget.dataset.id
   let image = this.data.tempFilePaths
  //  console.log(e,index,image);
   image.splice(index,1)
    this.setData({
      tempFilePaths:image
    })
  },
  // 发表文章
  getinfo(bid,title,content){
    a.post('sns/board_submit',{bid,title,content},(res) => {
        // console.log(this.data.id,this.data.title,this.data.content);
        // console.log(res)
        if(res.status==0){
          wx.showToast({
            title: '标题和内容最少3个汉字或字符',
            icon:'none'
          })
        }else{
          // 返回上一个页面
           wx.navigateBack({})
        }
    })
  },

// 获取title
  bindInputTitle(e){
    // console.log(e);
    let title=e.detail.value
    this.setData({
      title
    })
    // console.log(this.data.title);
    clearTimeout(this.TimeId)
    this.TimeId=setTimeout(() => {
      // this.getinfo(this.data.id,this.data.title,this.data.content)
    }, 500);
    },

    // 获取content
    bindInputContent(e){
      let content=e.detail.value
      this.setData({
        content
      })
      // console.log(this.data.content);
      clearTimeout(this.TimeId)
      this.TimeId=setTimeout(() => {
        // this.getinfo(this.data.id,this.data.title,this.data.content)
      }, 500);
    },
    //  发表文章
    submithandle(){

      this.getinfo(this.data.id,this.data.title,this.data.content)
      // console.log(this.data.id,this.data.title,this.data.content);
      
    },
})